/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if(headA == null || headB == null) {
            return null;
        }
        /**
        a+c=m,b+c=n
        每个节点走一遍a+b+c
         */
         ListNode curA = headA;
         ListNode curB = headB;
         while(curA != curB) {
             curA = curA == null ? headB : curA.next;
             curB = curB == null ? headA : curB.next;
         }
         return curA;
    }
}